package com.example.jacky.android_easeui.demo;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.jacky.android_easeui.R;
import com.example.jacky.android_easeui.base.BaseActivity;
import com.example.jacky.android_easeui.netapi.ResponseDto;
import com.example.jacky.android_easeui.netapi.model.SigninRewardPayload;
import com.example.jacky.android_easeui.netapi.retrofit.ServiceFactory;

import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by jacky on 2016/11/8.
 * sounbus app-developer
 */

public class RetrofitApiActivity extends BaseActivity {
    public static final String TAG = "RetrofitApiActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit_api);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.api_get, R.id.api_post})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.api_get:
                getApi();
                break;
            case R.id.api_post:
                break;
        }
    }

    private void getApi() {
        ServiceFactory.getRetrofitService().getSigninReward()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ResponseDto<SigninRewardPayload>>() {
                    @Override
                    public void onCompleted() {
                        Log.d(TAG, "onCompleted: ");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "onError: ");

                    }

                    @Override
                    public void onNext(ResponseDto<SigninRewardPayload> signinRewardPayloadResponseDto) {
                        Log.d(TAG, "onNext: ");

                    }
                });
    }
}
